#include <iostream>

using namespace std;

class a
{
public:
    int x;
    int y;
    a() {}
    a(int x1, int y1) : x(x1), y(y1) {}
};

class printA
{
public:
    void print(a a1)
    {
        cout << a1.x << " " << a1.y << endl;
    }
};

class printInt
{
public:
    void print(int x)
    {
        cout << x << endl;
    }
};

template <class T, class T2>
class dyArray
{
private:
    T *p;       // 数组指针
    int length; // 数组长度
public:
    dyArray(int n)
    {
        p = new T[n];
        length = 0;
    }
    void push_back(T elem)
    {
        p[length++] = elem;
    }
    void print_array() // print函数只负责遍历数据，打印的事情承包给外面的类或者函数
    {
        T2 val;
        for (int i = 0; i < length; i++)
        {
            val.print(p[i]);
        }
    }
};

int main(int argc, char const *argv[])
{
    dyArray<int, printInt> arr_1(10);
    for (int i = 1; i < 9; i++)
        arr_1.push_back(10 * i);
    arr_1.print_array();

    dyArray<a, printA> arr_2(10);
    for (int i = 1; i < 9; i++)
        arr_2.push_back(a(5 * i, 10 * i));
    arr_2.print_array();
    return 0;
}
